import {
    Controller,
    Post,
    HttpStatus,
    Body,
    HttpCode,
    Delete,
    Param,
    ParseIntPipe,
    Patch,
    Get,
    Query,
    UseGuards,
  } from '@nestjs/common';
  import { ApiTags, ApiOperation, ApiOkResponse } from '@nestjs/swagger';
  import { AccessService } from 'src/service/access/access.service';
  import { CreateAccessDto } from './dto/access.create.dto';
  import { UpdateAccessDto } from './dto/access.update.dto';
  import { AccessListVo, AccessVo } from './vo/access.vo';
  import { AccessReqDto } from './dto/access.req.dto';
  import { AuthGuard } from '@nestjs/passport';
  @ApiTags('后台管理系统-资源管理')
  @UseGuards(AuthGuard('jwt'))
  @Controller('access')
  export class AccessController {
    constructor(private readonly accessService: AccessService) {}
  
    @ApiOperation({ summary: '创建资源', description: '创建资源' })
    @ApiOkResponse({
      type: String,
      description: '创建资源返回值',
    })
    @Post()
    @HttpCode(HttpStatus.CREATED)
    async createAccess(@Body() createAccessDto: CreateAccessDto): Promise<string> {
      return await this.accessService.createAccess(createAccessDto);
    }
  
    @ApiOperation({ summary: '删除资源', description: '根据资源ID删除资源' })
    @Delete(':id')
    @HttpCode(HttpStatus.OK)
    async destroyAccessById(@Param('id', new ParseIntPipe()) id: number): Promise<string> {
      return await this.accessService.destroyAccessById(id);
    }
  
    @ApiOperation({ summary: '修改资源', description: '根据资源ID修改资源' })
    @ApiOkResponse({
      type: String,
      description: '修改资源的返回值',
    })
    @Patch(':id')
    async modifyAccessById(
      @Param('id', new ParseIntPipe()) id: number,
      @Body() updateAccessDto: UpdateAccessDto,
    ): Promise<string> {
      return await this.accessService.modifyAccessById(id, updateAccessDto);
    }
  
    @ApiOperation({
      summary: '获取菜单',
      description: '获取全部的菜单(不分页,给角色分配资源使用)',
    })
    @ApiOkResponse({
      type: AccessVo,
      isArray: true,
      description: '获取全部菜单返回DTO',
    })
    @HttpCode(HttpStatus.OK)
    @Get('access_list')
    async accessList(): Promise<AccessVo[]> {
      return await this.accessService.accessList();
    }
  
    @ApiOperation({
      summary: '获取资源列表',
      description: '分页获取资源列表(顶层的)',
      externalDocs: {
        url: 'xxx?pageSize=10&pageNumber=1',
      },
    })
    @ApiOkResponse({
      type: AccessListVo,
      description: '分页获取资源列表',
    })
    @Get()
    async accessListPage(@Query() accessReqDto: AccessReqDto): Promise<AccessListVo> {
      return await this.accessService.accessListPage(accessReqDto);
    }
  }
  